package com.atyjh.reggie.controller;

import com.atyjh.reggie.dto.Result;
import com.atyjh.reggie.dto.SetmealDto;
import com.atyjh.reggie.entity.Category;
import com.atyjh.reggie.entity.Setmeal;
import com.atyjh.reggie.service.ISetMealService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yjh
 * @since jdk1.8.0_311 2022.06.20
 */
@RestController
@RequestMapping("/setmeal")
@Slf4j
public class SetMealController {

    @Resource
    private ISetMealService setMealService;

    /**
     * 分页查询
     *
     * @param page 当前页页码
     * @param pageSize 每页数据数
     * @return 分页信息
     */
    @GetMapping("/page")
    public Result<Page<SetmealDto>> page(@RequestParam("page")Integer page,
                                         @RequestParam("pageSize")Integer pageSize,
                                         @RequestParam(value = "name", required = false)String name) {
        return setMealService.pageMeal(page, pageSize, name);
    }


    /**
     * 新增套餐
     *
     * @param setmealDto 套餐信息
     * @return 是否保存成功
     */
    @PostMapping
    public Result<String> save(@RequestBody SetmealDto setmealDto) {
        return setMealService.saveMeal(setmealDto);
    }

    @DeleteMapping
    public Result<String> delete(@RequestParam("ids")List<Long> ids) {
        return setMealService.delete(ids);
    }


    @GetMapping("/list")
    public Result<List<Setmeal>> list(@RequestParam("categoryId") Long categoryId, @RequestParam("status") String status) {

        return setMealService.listDish(categoryId, status);

    }

}
